﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Collections.Specialized;

namespace TrainingsApp.IPADApp.Master {
    public partial class SchoolManager : PageBase {
        protected void Page_Load(object sender, EventArgs e) {
            //if (!this.IsPostBack)
            Databinds();
        }


        protected void Databinds() {
            //Stopwatch watch = new Stopwatch();
            //watch.Start();
            StringDictionary where = new StringDictionary();
            if (!string.IsNullOrEmpty(this.txtCode.Text)) {

                where.Add("SchoolCode", this.txtCode.Text);
            }
            if (!string.IsNullOrEmpty(this.txtAddress.Text)) {

                where.Add("Address", this.txtAddress.Text);
            }
            if (!string.IsNullOrEmpty(this.txtSchoolName.Text)) {

                where.Add("SchoolName", this.txtSchoolName.Text);
            }

            var collection = TrainingsApp.Logic.TS_School_Logic.TS_School_ListToGridByPaging(this.aspDataSource.SettingsPager.PageSize, this.aspDataSource.PageIndex + 1, where);
           // return;
            this.aspDataSource.DataSource = GetAllPager(aspDataSource.PageIndex, this.aspDataSource.SettingsPager.PageSize, collection.TS_School_List, collection.TotalCount);
            this.aspDataSource.DataBind();
            //watch.Stop();
            //Response.Write(watch.ElapsedMilliseconds);
        }



        protected void aspDataSource_PageIndexChanged(object sender, EventArgs e) {
            Databinds();
        }

        protected void aspDataSource_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e) {
            long key = Convert.ToInt64(this.aspDataSource.GetRowValues(e.VisibleIndex, "Idx"));
            if (e.ButtonID == "btnEdit") {

                Response.Redirect("SchoolEdit.aspx?sid=" + key);
            }
            else if (e.ButtonID == "btnNew") {
                Response.Redirect("SchoolEdit.aspx");
            }
            else if (e.ButtonID == "btnManagerClass") {
                Response.Redirect("ClassManager.aspx?sid=" + key);
            }
            else if (e.ButtonID == "btnManagerTeacher") {
                Response.Redirect("TeacherManager.aspx?sid=" + key);
            }
            else { //btnManagerChildren
                Response.Redirect("ChildrenManager.aspx?sid=" + key);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e) {

        }
    }
}